package com.future.permission.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.future.permission.entity.SysAclModule;
import com.future.permission.mapper.SysAclModuleMapper;
import com.future.permission.param.TestVo;
import com.future.permission.result.R;
import com.future.permission.utils.ApplicationContextHelper;
import com.future.permission.utils.SpringContext;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.Arrays;

/**
 * @Author yinhao
 * @Date 2021/3/30 18:36
 * @Description 测试Controller
 */
@RestController
@RequestMapping("/test")
public class TestController {

    /**
     * 你好
     *
     * @return
     */
    @RequestMapping(value = "/hello", method = RequestMethod.GET)
    public R hello() {
//        JSONObject object = JSON.parseObject("{'upPacketSN':-1,'upDataSN':-1,'topic':'v1/up/ad19','timestamp':1617172207604,'tenantId':'2000031842','serviceId':12,'protocol':'lwm2m','productId':'15039192','payload':{'VER':1,'TIME':15,'TEMP':201,'STC':94,'RSSI':18,'HUMI':564,'BAT':3600},'messageType':'dataReport','deviceType':'','deviceId':'488200bd80e14a97826c95834dee135e','assocAssetId':'','IMSI':'undefined','IMEI':'864333043632975'}");
//        System.out.println(object);
//
//                int i = 1/0;
        return R.ok().put("welcome", "hello permission");
    }


    @RequestMapping("/validate")
    public R validate(@Valid @RequestBody TestVo testVo) {
        return R.ok();
    }

    @RequestMapping("/application")
    public R application(){
//        String[] beanDefinitionNames = SpringContext.getBeanDefinitionNames();
//        for (String beanDefinitionName : beanDefinitionNames) {
//            System.out.println(beanDefinitionName);
//        }
        SysAclModuleMapper sysAclModuleMapper = ApplicationContextHelper.popBean(SysAclModuleMapper.class);
        SysAclModule sysAclModule = sysAclModuleMapper.selectByPrimaryKey(1);
        return R.ok().put("sysAclModule",sysAclModule);
    }


}
